package com.loongtech.bi.action.player;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.loongtech.bi.action.BaseBiSearchAction;
import com.loongtech.bi.manager.player.VersionAndHardwarePlayerManager;
import com.loongtech.bi.manager.player.VersionAndHardwarePlayerManager.UserLoginLocationCityData;
import com.loongtech.bi.manager.player.VersionAndHardwarePlayerManager.UserLoginLocationProvinceData;
import com.loongtech.bi.manager.system.SysLogManager;
import com.loongtech.bi.support.Session;
import com.loongtech.bi.support.chart.ChartTool;
import com.loongtech.bi.support.chart.ChartType;
import com.loongtech.bi.support.chart.ChartUIData;

/**
 * 玩家分析-留存分析Action
 * @author Marin
 * @date 2015年09月17日
 */
@Controller
@Scope("view")
public class VersionAndHardwarePlayerAction extends BaseBiSearchAction {
	private static final long serialVersionUID = 1L;
	private List<UserLoginLocationCityData> dataList1;  // 前端要显示的数据1
	private ChartUIData chartData1;  // 前端要显示的柱状图1数据
	
	private List<UserLoginLocationProvinceData> dataList2;  // 前端要显示的数据1
	private ChartUIData chartData2;  // 前端要显示的柱状图1数据
	
	@Autowired
	private VersionAndHardwarePlayerManager versionAndHardwarePlayerManager;
	
	@Autowired
	private SysLogManager sysLogManager;
	@Autowired
	private Session session;
	
	@PostConstruct
	public void init() {
		search();
	}

	public void search() {
		sysLogManager.addLog(session.getUserName(), "玩家分析-留存分析");
		
		chartData1 = null;
		chartData2 = null;
		dataList1 = versionAndHardwarePlayerManager.getUserLoginLocationCityData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		
		if (dataList1 != null && dataList1.size() > 0) {
			chartData1 = new ChartUIData();
			chartData1.setJsonType(ChartType.COLUMN.type);
			chartData1.setJsonStr(new ChartTool(dataList1, UserLoginLocationCityData.class, "").loadData(chartData1.getJsonType()));
		}
	
		dataList2 = versionAndHardwarePlayerManager.getUserLoginLocationProvinceData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		if (dataList2 != null && dataList2.size() > 0) {
			chartData2 = new ChartUIData();
			chartData2.setJsonType(ChartType.COLUMN.type);
			chartData2.setJsonStr(new ChartTool(dataList2, UserLoginLocationProvinceData.class, "").loadData(chartData2.getJsonType()));
		}
	}
	
	@Override
	protected String csvContent() {
		return "用户地域分布";
	}

	@Override
    protected String csvFileName() {
	    return "用户地域分布";
    }

	public List<UserLoginLocationCityData> getDataList1() {
		return dataList1;
	}

	public void setDataList1(List<UserLoginLocationCityData> dataList1) {
		this.dataList1 = dataList1;
	}

	public ChartUIData getChartData1() {
		return chartData1;
	}

	public void setChartData1(ChartUIData chartData1) {
		this.chartData1 = chartData1;
	}

	public List<UserLoginLocationProvinceData> getDataList2() {
		return dataList2;
	}

	public void setDataList2(List<UserLoginLocationProvinceData> dataList2) {
		this.dataList2 = dataList2;
	}

	public ChartUIData getChartData2() {
		return chartData2;
	}

	public void setChartData2(ChartUIData chartData2) {
		this.chartData2 = chartData2;
	}
}
